package com.example.test.config.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.DefaultParameterNameDiscoverer;

import java.lang.reflect.Method;

//@Aspect
//@Component
public class ParamCheckContoller implements ApplicationContextAware {


    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    @Pointcut("execution(* com.example.test.Controller.*(..))")
    public void checkParam() {
    }


    @Before(value = "checkParam()")
    public void before(JoinPoint joinPoint) {
        Signature signature = joinPoint.getSignature();
        MethodSignature methodSignature = (MethodSignature) signature;
        Method method = methodSignature.getMethod();

        System.out.println(method);

        Object[] args = joinPoint.getArgs();

        String[] parameterNames = new DefaultParameterNameDiscoverer().getParameterNames(method);

        for (int i = 0; i < args.length; i++) {
            System.out.println(args[i]);
            System.out.println(parameterNames[i]);
        }

//        AdpterBean adpterBean = new AdpterBean(basicArea1,false);
//
//        System.out.println(JSONUtil.toJsonStr(adpterBean.get()));
//
//
//        boolean flag = checkParam(adpterBean.get(),false);

    }

}

